//
//  BabyNameViewController.m
//  Toyohu
//
//  Created by Heige on 16/4/20.
//  Copyright © 2016年 celia. All rights reserved.
//

#import "BabyNameViewController.h"
#import <Masonry.h>

#import "UIView+Fillet.h"

#define WIDTH self.view.bounds.size.width
#define HEIGHT self.view.bounds.size.height
@interface BabyNameViewController ()
{
    UITextField *myName;
}

@end

@implementation BabyNameViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    myName = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 2*WIDTH/3, 40)];
    myName.center = CGPointMake(WIDTH/2, 100);
    myName.tag = 200;
    myName.placeholder = @"请输入名字";
    myName.borderStyle = UITextBorderStyleRoundedRect;
    myName.clearButtonMode = UITextFieldViewModeAlways;
    [myName becomeFirstResponder];
    [self.view addSubview:myName];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    [button setTitle:@"完成" forState:UIControlStateNormal];
   button.layer.cornerRadius = 20;
    button.clipsToBounds  =YES;
  //  [button filletWithcornerRadius:20];
    [button setBackgroundColor:[UIColor orangeColor]];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(done) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
    
    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(myName.mas_centerX);
        make.top.equalTo(myName.mas_bottom).offset(10);
        make.width.equalTo(@(2*WIDTH/3));
        make.height.equalTo(@(40));
        
    }];
}


-(void)done{
    UITextField *name = (id)[self.view viewWithTag:200];
    NSString *str = name.text;
    
    NSUserDefaults *userDef = [NSUserDefaults standardUserDefaults];
    [userDef setObject:str forKey:@"babyname"];
    [userDef synchronize];
    
    [myName resignFirstResponder];
    [self dismissViewControllerAnimated:YES completion:nil];
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
